<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>购物车</title>
    <script type="text/javascript" src="__PUBLIC__/Js/home/jquery-1.11.3.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Js/layer/layer.js"></script>
    <script>
        //要写在user_common.js调用之前     因tp框架中定义的常量，在外部调用的js中不能被解析
        var tp_defined = {'url': '__URL__'};
    </script>
    <script type="text/javascript" src="__PUBLIC__/Js/home/user_common.js"></script>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Css/home/cart.css">
    <script>
        $(function () {
            var checkbox = $('.shop_tabble input:checkbox');
            if (checkbox.length == 0) {
                return;
            }
            //全选
            $('.save .all').click(function () {
                checkbox.prop('checked', true);
            });
            //全不选
           /* $('.save .none').click(function () {
                checkbox.prop('checked', false);
            });*/
            //反选
            $('.save .reverse').click(function () {
                for (var i = 0; i < checkbox.length; i++) {
                    if (checkbox.eq(i).prop('checked')) {
                        checkbox.eq(i).prop('checked', false);
                    } else {
                        checkbox.eq(i).prop('checked', true);
                    }
                }
            });
            //商品数量和价格的动态变动
            $(document).click(function () {
                //获取选择的商品数
                var checked_num = $('.shop_tabble input:checkbox:checked');
                //$('.checked_num').html(checked_num.length);
                //获取选取商品的总价
                var good_num = 0;
                var total = 0;
                if(checked_num.length!=0){
                    for (var i = 0; i < checked_num.length; i++) {
                        var td = checked_num.eq(i).parents('tr');
                        good_num += parseInt(td.children('.good_num').children('span').text());
                        total += parseInt(td.children('.good_total').text());
                    }
                    $('.end_bt').css({'background-color':'#D6B870','cursor':'pointer'});
                    $('.end_bt').attr('onclick','submitOrder()');
                }else{
                    $('.end_bt').css({'background-color':'#B0B0B0','cursor':''});
                    $('.end_bt').removeAttr('onclick');
                }
                $('.checked_num').html(good_num);
                $('.fw_bold').html('￥' + total);
            });
        });
        //提交订单  填写收货地址
        function submitOrder(){
            //获取选择的商品的购物车对应的id
            $('#orderForm').submit();
        }
    </script>
</head>
<body>
<!--全部背景-->
<div class="all-thing">
    <!--中间内容-->
    <div class="tcmain">
        <!--引入购物车头部文件-->
        <include file="Common/cart_header"/>
        <!--导航条-->
        <div id="ctl00_showNav" class="shop_spnav"></div>
        <!--导航条end-->
        <!--内容-->
        <div class="shop_cort">
            <form method="post" action="__URL__/sureOrder" id="orderForm">
                <!--左边-->
                <div class="shop_cort-left fl">
                    <!--<h3>查看我的购物车</h3>-->
                    <!--购物车-->
                    <div class="save">
                        <a href="javascript:void(0)" class="all">全选</a>
                        <!--<a href="javascript:void(0)" class="none">全不选</a>-->
                        <a href="javascript:void(0)" class="reverse">反选</a>
                    </div>
                    <table class="shop_tabble" border="0" cellpadding="0" cellspacing="0">
                        <tr class="nav_tr">
                            <td class="gm_td"></td>
                            <td class="sp_td">商品</td>
                            <td class="cz_td">材质</td>
                            <!--<td class="sc_td">手寸/尺寸</td>
                            <td class="kz_td">刻字</td>-->
                            <td class="kz_td">单价(￥)</td>
                            <td class="kz_td">购买量</td>
                            <td class="gm_td">购买价(￥)</td>
                        </tr>
                        <eq name="cart_data|count" value="0">
                            <tr>
                                <td colspan="7">购物车空空的，去寻找真爱吧 :)</td>
                            </tr>
                        </eq>
                        <foreach name="cart_data" item="v">
                            <tr class="nav_tr_main">
                                <td><input type="checkbox" name="checked[]" value="{$v['id']}"></td>
                                <td class="sp_td"><a href="__MODULE__/Goods/details/id/{$v['goods_detail_id']}">{$v['goods_style']}{$v['goods_name']}</a></td>
                                <td>
                                    <switch name="v['material']">
                                        <case value="0">白18K金</case>
                                        <case value="1">PT950</case>
                                    </switch>
                                </td>
                                <!--<td>{$v['size']}</td>
                                <td>{$v['carve']}</td>-->
                                <td class="good_price">{$v['price']}</td>
                                <td class="good_num">
                                    <a href="javascript:num_change({$v['id']},'cut')" class="cut">-</a>
                                    <span class="cart_{$v['id']}">{$v['num']}</span>
                                    <a href="javascript:num_change({$v['id']},'add')" class="add">+</a>
                                </td>
                                <td class="good_total">{$v['price']*$v['num']}</td>
                            </tr>
                        </foreach>
                    </table>
                    <!--购物车end-->

                    <!--结算-->
                    <div class="shop_js">
                        <div class="left">
                            <a href="javascript:delCart();" class="del_shop">删除选中项</a>
                            <a href="javascript:clearCart();" class="qk_shop">清空购物车</a>
                            <a href="__MODULE__/Goods/index" class="jx_shop">继续购物</a>
                        </div>
                        <div class="right">
                            <span>你选择了<i class="checked_num">0</i>件商品</span>
                            <span>总计：<i class="fw_bold" style="font-family: 微软雅黑;">￥0</i></span>
                            <span class="end_bt"><em>立即结算</em></span>
                        </div>
                    </div>
                    <!--结算end-->
                </div>
                <!--左边end-->
            </form>
            <!--引入购物车右侧文件-->
            <include file="Common/cart_right"/>
        </div>
        <!--引入购物车底部文件-->
        <include file="Common/cart_footer"/>
    </div>
    <!--全部背景end-->
</div>
</body>
</html>
